package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.TiZhiBianSHiMapper;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.GanYu;
import com.itheima.pojo.Problem;
import com.itheima.service.TiZhiBianSHiService;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;

@Service(version = "1.0.0",interfaceClass = TiZhiBianSHiService.class)
public class TiZhiBianSHiServiceImpl implements TiZhiBianSHiService {

    @Resource
    private TiZhiBianSHiMapper tiZhiBianSHiMapper;

    @Override
    public Result findAll(QueryPageBean queryPageBean) throws ParseException {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<GanYu> list = tiZhiBianSHiMapper.findAll();
        for (GanYu ganYu : list) {
            ganYu.setDate(new SimpleDateFormat("yyyy-MM-DD").parse(new SimpleDateFormat("yyyy-MM-DD").format(ganYu.getDate())));
        }
        PageInfo<GanYu> pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo);
    }

    @Override
    public Result del(Integer id) {
        tiZhiBianSHiMapper.del(id);
        return Result.success(null);
    }

    @Override
    public Result update(GanYu ganYu) {
        tiZhiBianSHiMapper.update(ganYu);
        return Result.success(null);
    }

    @Override
    public Result getProblem() {
        List<Problem> list = tiZhiBianSHiMapper.getProblem();
        return Result.success(list);
    }

    @Override
    public Result add(GanYu ganYu) {
         tiZhiBianSHiMapper.add(ganYu);
         return Result.success(null);
    }
}
